package tv.youxing.android.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import tv.youxing.android.R;

/**
 * Created by apple on 2017/4/17.
 */

/**
 * 项目名：   youxing
 * 包名：     tv.youxing.android .fragment
 * 文件名：   SubscribeFragment
 * 创建者：   叶克武
 * 创建时间： 2017/4/17 下午2:48
 * 描述：    TODO
 */
public class SubscribeFragment extends BaseFragment {

    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private List<String> mTitle;
    private List<Fragment> mFragment;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_subscribe, null);
        initData();
        findView(view);
        return view;
    }


    private void initData(){

        mTitle = new ArrayList<>();
        mTitle.add("已订");
        mTitle.add("推荐");

        mFragment = new ArrayList<>();
        mFragment.add(new OrderedFragment());
        mFragment.add(new RecommendFragment());

    }


    private void findView(View view) {
        mTabLayout = (TabLayout) view.findViewById(R.id.mTabLayout);
        mViewPager = (ViewPager) view.findViewById(R.id.mViewPager);

        mViewPager.setOffscreenPageLimit(mFragment.size());

        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                switch (position){
                    case 0:

                        break;
                    case 1:

                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        mViewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {

            @Override
            public Fragment getItem(int position) {
                return mFragment.get(position);
            }

            @Override
            public int getCount() {
                return mFragment.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mTitle.get(position);
            }

        });

        mTabLayout.setupWithViewPager(mViewPager);

    }



}
